 package CurtainDesign;

 import CurtainDesign.utils.CalculateUtils;
 import CurtainDesign.utils.CurtainChecker;
 import CurtainDesign.utils.HingeRelatedInfo;
 import CurtainDesign.utils.Translator;
 import NewOrderXmlbean.Comments;
 import NewOrderXmlbean.Levelinfo;
 import NewOrderXmlbean.OrderDocument;
 import NewOrderXmlbean.OrderDocument.Factory;
 import NewOrderXmlbean.Orderinfo;
 import java.io.File;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import javax.swing.JOptionPane;

 /**
  * 折叠形订单
  */
 public class OrderFileByFold extends OrderFile
 {
   public boolean ReadOrderFile(String orderfile)
   {
     try
     {
       File xmlfile = new File(orderfile);
       OrderDocument doc = OrderDocument.Factory.parse(xmlfile);
       Orderinfo orderinfo = doc.getOrder();
       Translator.english2Chinese(orderinfo);
       Levelinfo info = orderinfo.getLevelArray(0);

       String tmp = orderinfo.getWindowtype();
       if (!CurtainChecker.isEmpty(tmp))
       {
         int index = -1;
         for (int i = 0; i < Constants.STYLES.length; i++)
         {
           if (!tmp.equals(Constants.STYLES[i]))
             continue;
           index = i;
           break;
         }

         if (index > -1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveStyle(index);
         }

       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取WindowType错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getOrderindex();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOrderIndex(tmp);
       } else {
         JOptionPane.showMessageDialog(null, "读取OrderIndex错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getClientregion();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveClientRegion(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取ClientRegion错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getRoom();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveRoom(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Room错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getPipeindex();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePipeIndex(tmp);
       }
       else
       {
         String tmppipe = CurtainDesign.m_PipeIndexFile.GetPipeIndex(Constants.STYLES[1], true);
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePipeIndex(tmppipe);
       }

       tmp = orderinfo.getOrderdate();
       if (!CurtainChecker.isEmpty(tmp))
       {
         DateFormat dtformat = new SimpleDateFormat("ddMMyyyy");
         Date date = dtformat.parse(tmp);
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOrderDate(date);

         long lDate = date.getTime() + 691200000L;
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDeliverDate(new Date(lDate));
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Order Date错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getCustomerrefnum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().saveCustRefNum(tmp);
       }

       tmp = orderinfo.getWindowtype();
       if ((tmp == null) || (tmp.equals("")) || (!tmp.equals(Constants.STYLES[1]))) {
         JOptionPane.showMessageDialog(null, "窗户类型错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getWindownum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWindowNum(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取WindowNum错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getWindowindex();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWindowIndex(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取WindowIndex错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getWoodoption();
       if (!CurtainChecker.isEmpty(tmp))
       {
         int index = -1;
         for (int i = 0; i < Constants.WOODOPTION.length; i++)
         {
           if (!Constants.WOODOPTION[i].equals(tmp))
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWoodOption(index);
         }
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取HingeType错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getColor();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveColor(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Color错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getOriwindowwidth();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOriWindowWidth(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取OriWindowWidth错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getOriwindowheight();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOriWindowHeight(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取OriWindowHeight错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getInstall();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveInstall(tmp);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Install错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getHingecolor();
       if (!CurtainChecker.isEmpty(tmp))
       {
         int index = -1;
         for (int i = 0; i < Constants.HINGECOLOR.length; i++)
         {
           if (!Constants.HINGECOLOR[i].equals(tmp))
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveHingeColor(index);
         }
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Hinge Color错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = orderinfo.getPullbartype();
       if (!CurtainChecker.isEmpty(tmp))
       {
         int index = -1;
         for (int i = 0; i < Constants.PULLBARTYPE.length; i++)
         {
           if (!Constants.PULLBARTYPE[i].equals(tmp))
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePullBarType(index);
         }

       }
       else if (!info.getBoard())
       {
         JOptionPane.showMessageDialog(null, "读取PullBar错误，请检查", "读文件错误", 0);
         return false;
       }

       boolean isRoundMegnet = orderinfo.getRoundmagnet();
       CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveIsRoundMagnet(isRoundMegnet);

       boolean isAutoAddDivider = orderinfo.getAutoadddivider();
       CurtainDesign.m_UserMainGUI.GetOrderInfo().saveAutoAddDivider(isAutoAddDivider);

       tmp = info.getHingeinstalltype();
       if (!CurtainChecker.isEmpty(tmp))
       {
         tmp = CalculateUtils.formatHingeInstallType(tmp);
         if (!CurtainChecker.isVaildByFoldNum(tmp))
         {
           JOptionPane.showMessageDialog(null, "窗扇数量必须为偶数！", "错误", 0);
           return false;
         }
         if (CurtainChecker.isVaildHingeInstall(tmp.trim().toUpperCase(), CurtainChecker.byFoldRegex))
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveHingeInstallType(tmp);
           HingeRelatedInfo hingeInfo = CalculateUtils.getByFoldHingeRelatedInfo(tmp);

           CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePanelNum(new Integer(hingeInfo.getPaneNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().saveBendHinge(new Integer(hingeInfo.getBendHingePaneNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveSingleHinge(new Integer(hingeInfo.getSingleHingePaneNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDoubleHinge(new Integer(hingeInfo.getDoubleHingePaneNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePoleNum(new Integer(hingeInfo.getPoleNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDuiKouPoleNum(new Integer(hingeInfo.getDuikouPoleNum()).toString());

           CurtainDesign.m_UserMainGUI.GetOrderInfo().saveShuangLianPoleNum(new Integer(hingeInfo.getShuanglianPoleNum()).toString());

           DecimalFormat nFormat = new DecimalFormat();
           nFormat.setMaximumFractionDigits(2);
           nFormat.setGroupingSize(10);
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveGap(nFormat.format(hingeInfo.getGap()));
         }
         else
         {
           JOptionPane.showMessageDialog(null, "合页安装方式不合法，请检查！", "读文件错误", 0);

           return false;
         }
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Hinge Install Type错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = info.getPanelnum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePanelNum(tmp);
       }

       tmp = info.getSinglehinge();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveSingleHinge(tmp);
       }

       tmp = info.getDoublehinge();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDoubleHinge(tmp);
       }

       tmp = info.getBendhinge();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().saveBendHinge(tmp);
       }

       tmp = info.getShuanglianpolenum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().saveShuangLianPoleNum(tmp);
       }

       tmp = info.getPolenum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePoleNum(tmp);
       }

       tmp = info.getDuikoupolenum();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDuiKouPoleNum(tmp);
       }

       tmp = info.getGap();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveGap(tmp);
       }

       boolean isBoard = info.getBoard();
       CurtainDesign.m_UserMainGUI.GetOrderInfo().saveIsBoard(isBoard);

       tmp = info.getVanetype();
       if (!CurtainChecker.isEmpty(tmp))
       {
         int index = -1;
         for (int i = 0; i < Constants.VANETYPE.length; i++) {
           if (!Constants.VANETYPE[i].equals(tmp))
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveVaneType(index);
         }

       }
       else if (!info.getBoard())
       {
         JOptionPane.showMessageDialog(null, "读取VaneType错误，请检查", "读文件错误", 0);

         return false;
       }

       tmp = info.getDividertype();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         float fDividerWidth = new Float(tmp).floatValue();
         for (int i = 0; i < Constants.DIVIDERTYPE.length; i++)
         {
           if (new Float(Constants.DIVIDERTYPE[i]).floatValue() != fDividerWidth)
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(index);
         }

       }
       else if ((!info.getBoard()) && (!CurtainChecker.isEmpty(info.getDividernum())))
       {
         int vanetype = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetVaneType();
         if ((vanetype == 0) || (vanetype == 2)) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(2);
         }
         else if (vanetype == 1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(0);
         }
         else if (vanetype == 3)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(1);
         }
         else
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(3);
         }

       }

       tmp = info.getDividernum();

       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerNum(tmp);
       }
       else
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerNum("0");
       }

       tmp = info.getDividerpos();
       if (!CurtainChecker.isEmpty(tmp))
       {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerPos(tmp);
       }
       else if ((!info.getBoard()) && (!CurtainChecker.isEmpty(info.getDividernum())) && (Integer.parseInt(info.getDividernum()) == 0)) {
         JOptionPane.showMessageDialog(null, "读取DividerPos错误，请检查", "读文件错误", 0);
         return false;
       }

       Comments comments = orderinfo.getComments();
       if (comments != null)
       {
         StringBuffer buff = new StringBuffer();
         int i = 0; for (int j = comments.getCommentArray().length; i < j; i++)
         {
           buff.append(comments.getCommentArray()[i]).append("@@");
         }
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveComments(buff.toString());
       }
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
     return true;
   }

   public void WriteOrderFile(String orderfile, boolean newopenedfile, boolean override)
   {
     try
     {
       File xmlfile = new File(orderfile);
       OrderDocument doc = OrderDocument.Factory.newInstance();
       Orderinfo orderinfo = doc.addNewOrder();

       orderinfo.setWindowtype(Constants.STYLES[1]);

       String tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOrderIndex();
       orderinfo.setOrderindex(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetClientRegion();
       orderinfo.setClientregion(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetRoom();
       orderinfo.setRoom(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPipeIndex();
       orderinfo.setPipeindex(tmpStr);

       Date tmpdate = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOrderDate();
       DateFormat dtformat = new SimpleDateFormat("ddMMyyyy");
       orderinfo.setOrderdate(dtformat.format(tmpdate));

       long lDate = tmpdate.getTime() + 691200000L;
       tmpdate = new Date(lDate);
       orderinfo.setDeliverdate(dtformat.format(tmpdate));

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().getCustRefNum();
       if (!CurtainChecker.isEmpty(tmpStr))
       {
         orderinfo.setCustomerrefnum(tmpStr);
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWindowNum();
       orderinfo.setWindownum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWindowIndex();
       orderinfo.setWindowindex(tmpStr);

       int tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWoodOption();
       if (tmpint > -1)
       {
         orderinfo.setWoodoption(Constants.WOODOPTION[tmpint]);
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetColor();
       if (!CurtainChecker.isEmpty(tmpStr))
       {
         orderinfo.setColor(tmpStr);
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOriWindowWidth();
       orderinfo.setOriwindowwidth(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOriWindowHeight();
       orderinfo.setOriwindowheight(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetInstall();
       orderinfo.setInstall(tmpStr);

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetHingeColor();
       if (tmpint > -1)
       {
         orderinfo.setHingecolor(Constants.HINGECOLOR[tmpint]);
       }

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPullBarType();
       if (tmpint > -1)
       {
         orderinfo.setPullbartype(Constants.PULLBARTYPE[tmpint]);
       }

       orderinfo.setRoundmagnet(CurtainDesign.m_UserMainGUI.GetOrderInfo().IsRoundMagnet());

       orderinfo.setAutoadddivider(CurtainDesign.m_UserMainGUI.GetOrderInfo().getAutoAddDivider());

       Levelinfo level = orderinfo.addNewLevel();

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetHingeInstallType();
       level.setHingeinstalltype(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPanelNum();
       level.setPanelnum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetSingleHinge();
       level.setSinglehinge(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDoubleHinge();
       level.setDoublehinge(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().getBendHinge();
       level.setBendhinge(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().getShuangLianPoleNum();
       level.setShuanglianpolenum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPoleNum();
       level.setPolenum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDuiKouPoleNum();
       level.setDuikoupolenum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetGap();
       level.setGap(tmpStr);

       level.setBoard(CurtainDesign.m_UserMainGUI.GetOrderInfo().getIsBoard());

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetVaneType();
       if (tmpint > -1)
       {
         level.setVanetype(Constants.VANETYPE[tmpint]);
       }
       else
       {
         level.setVanetype("");
       }

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDividerType();
       if (tmpint > -1)
         level.setDividertype(Constants.DIVIDERTYPE[tmpint]);
       else {
         level.setDividertype("");
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDividerNum();
       level.setDividernum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDivederPos();
       level.setDividerpos(tmpStr);

       orderinfo.setLevelArray(new Levelinfo[] { level });

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetComments();
       if (!CurtainChecker.isEmpty(tmpStr))
       {
         String[] commentsArray = tmpStr.split("@@");
         Comments comments = orderinfo.addNewComments();
         comments.setCommentArray(commentsArray);
         orderinfo.setComments(comments);
       }
       Translator.chinese2English(orderinfo);
       doc.save(xmlfile);
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
   }
 }

/* Location:           C:\Users\Administrator\Desktop\奥特百叶窗\Shutter DesignerV3.1\CurtainDesign.jar
 * Qualified Name:     CurtainDesign.OrderFileByFold
 * JD-Core Version:    0.6.0
 */